home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / proboard / pb_215.zip / CPPDATE.HPP < prev    next >
C/C++ Source or Header  |  1996-05-05  |  3KB  |  95 lines

  1. #define TODAY (-1L)
  2.  
  3. class Date
  4.    {
  5.       char _d ,
  6.            _m ,
  7.            _y ;
  8.  
  9.       int compare(Date&)        const;
  10.  
  11.       static char *weekdays[7];
  12.       static char *s_weekdays[7];
  13.       static char *l_weekdays[7];
  14.       static char *months[12];
  15.       static char *l_months[12];
  16.  
  17.    public:
  18.       Date();                   // Initializes date to nothing
  19.       Date(long);               // Initializes date to julian/today
  20.       Date(int,int,int);        // Initializes date with specific values
  21.  
  22.       void operator()(int day,int month,int year) // Equal to set()
  23.          {
  24.             set(day,month,year);
  25.          }
  26.  
  27.       char& operator[](int i);  // 0 = day , 1 = month , 2 = year
  28.  
  29.       int day() const           // Returns day (1-31)
  30.          {
  31.             return _d;
  32.          }
  33.       int month() const         // Returns month (1-12)
  34.          {
  35.             return _m;
  36.          }
  37.       int year() const          // Returns year (0-127)
  38.          {
  39.             return _y;
  40.          }
  41.  
  42.       bool ok() const;           // Returns !=0 if date is valid
  43.  
  44.       int dayNum() const;       // Returns the number of the day in the year (1-366)
  45.       int weekDay() const;      // Returns the day of week (0=sunday)
  46.       int weekNum() const;      // Returns the week number (1-53)
  47.       int daysInMonth(int = 0) const; // Returns # days in given month
  48.       int daysInYear(int = 0) const;  // Returns # days in given year
  49.       int weeksInYear(int = 0) const; // Returns # weeks in given year
  50.  
  51.       operator long() const;    // Converts to julian date
  52.       Date& operator=(long);    // Converts julian date to normal date
  53.  
  54.       void operator++()
  55.          {
  56.             (*this) = long(*this) + 1;
  57.          }
  58.       void operator++(int)
  59.          {
  60.             operator++();
  61.          }
  62.       void operator--()
  63.          {
  64.             (*this) = long(*this) - 1;
  65.          }
  66.       void operator--(int)
  67.          {
  68.             operator--();
  69.          }
  70.       void operator+=(int n)
  71.          {
  72.             (*this) = long(*this) + n;
  73.          }
  74.       void operator-=(int n)
  75.          {
  76.             (*this) = long(*this) - n;
  77.          }
  78.  
  79.       void set(int,int,int);    // Set date to a specific date
  80.       void today();             // Set date to today
  81.  
  82.       int operator<(Date&) const;     //  ]
  83.       int operator>(Date&) const;     //  ]
  84.       int operator==(Date&) const;    //  ] Compare
  85.       int operator!=(Date&) const;    //  ]      functions
  86.       int operator<=(Date&) const;    //  ]
  87.       int operator>=(Date&) const;    //  ]
  88.  
  89.       int operator-(Date&) const;     // Returns difference in number of days
  90.  
  91.       bool leap()               const;
  92.  
  93.       void fileDate(word);  // Sets date to packed date
  94.    };
  95.